package com.yc.Testjvm.cglib.demo2;

import net.sf.cglib.proxy.Enhancer;

public class Test {
	
	public void testcglib() {
		BookProxyLib cglib=new BookProxyLib(); 
		BookProxyImpl bookCglib=(BookProxyImpl)cglib.getInstance(new BookProxyImpl()); 
		bookCglib.addBook(); 
	}
	
	/**
	 * 等效写法
	 */
	public void dxxf() {
		BookProxyLib bpl = new BookProxyLib();
		
		Enhancer enhancer = new Enhancer();
		enhancer.setSuperclass(BookProxyImpl.class);
		enhancer.setCallback(bpl);
		BookProxyImpl bp = (BookProxyImpl)enhancer.create();
		bp.addBook();
	}
	
	/**
	 * 优化写法
	 */
	public void yhxf() {
		BookProxyImpl bookCglib=(BookProxyImpl)(new BookProxyLib().getInstance2(BookProxyImpl.class)); 
		bookCglib.addBook(); 
	}

	public static void main(String[] args) {
		Test t = new Test();
//		t.testcglib();
//		t.dxxf();
		t.yhxf();

	}

}
